#!/usr/bin/env python
import sys, re
from model import *
from querymanager import *
    
if __name__ == "__main__":
    arg = sys.argv[1:]
    if len(arg) < 2:
        print '''Usage: query <dictionary.txt> <postings.txt>\n       Terminate with Ctrl+d'''
    try:
        import psyco
        psyco.full()
    except:
        pass
    advanced = False
    if '-a' in arg:
        advanced = True
    index = Index.fromFile(arg[0],arg[1],True)
    qm = QueryManager(index)
    LIMIT = 10
    line = sys.stdin.readline()
    while line:
        qm.handle(input=line, limit=LIMIT, ranked=True, advanced=advanced)
        line = sys.stdin.readline()
        